<?php

namespace app\system\validate;

use think\helper\Arr;
use think\Validate;

class MarkerValidate extends Validate
{
    protected $rule = [
        'name' => 'require|max:255',
        'category_id' => 'require|integer',
        'lng' => 'require|checkLngLat',
        'lat' => 'require|checkLngLat',
        'image_id' => 'integer',
        'voice_id' => 'integer',
        'qrcode_id' => 'integer',
        'intro' => 'max:1000',
    ];


    protected function checkLngLat($value, $rule, $data = [])
    {
        $lng = Arr::get($data, 'lng');
        $lat = Arr::get($data, 'lat');
        if ($lng >= -180 && $lng <= 180) {
            // 纬度验证
            if ($lat >= -90 && $lat <= 90) {
                return true;
            }
        }
        return false;
    }
}